package com.zyy.smartcity1129.util;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName: DateStringUtil$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 2/12/2021$
 * @Version: 1.0
 */
public class DateStringUtil {
    public static Date stringToDate(String dateString){
        ParsePosition position = new ParsePosition(0);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDateFormat.parse(dateString,position);
    }


    public static String dateToString(Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    public static String HHToTime(String dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH");
        Date date = stringToDate(dateDate);
        String dateString = formatter.format(date);
        if (Integer.parseInt(dateString) < 12) {
            dateString = "上午";
        } else {
            dateString = "下午";
        }
        return dateString;
    }
    public static String stringToTime(String dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
        Date date = stringToDate(dateDate);
        String dateString = formatter.format(date);
        return dateString;
    }
    public static String stringToYYMMDD(String dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = stringToDate(dateDate);
        String dateString = formatter.format(date);
        return dateString;
    }

    public static String stringToWeek(String dateString) {
        SimpleDateFormat format = new SimpleDateFormat("E");
        Date date = stringToDate(dateString);
        String week = format.format(date);
        return week;
    }
}
